using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Prsrp
{
    /// <summary>
    /// Main Game class.
    /// In a nutshell, this class hold a pointer to itself an to a <typeparamref name="GameEngine"/> instance.
    /// </summary>
    public class Game : Microsoft.Xna.Framework.Game
    {

        #region Properties

        // Game Singleton
        private static Game mpSingletonInstance;
        public static Game Instance
        {
            get { return mpSingletonInstance; }
        }

        // Game Engine Singleton
        private static GameEngine mpGameEngine;
        public static GameEngine Engine
        {
            get { return mpGameEngine; }
        }

        // Game Editor Singleton
        private static GameEditor mpGameEditor;
        public static GameEditor Editor
        {
            get { return mpGameEditor; }
        }

        #endregion

        #region Xna Functions

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run. 
        /// This is where it can query for any required services and load any non-graphic related content.  
        /// Calling base.Initialize will enumerate through any components and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            mpGameEngine.Initialize();
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load all of your content. 
        /// </summary>
        protected override void LoadContent()
        {
            mpGameEngine.LoadContent();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload all content.
        /// </summary>
        protected override void UnloadContent()
        {
            mpGameEngine.UnloadContent();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio.
        /// </summary>
        protected override void Update(GameTime _pGameTime)
        {
            mpGameEngine.Update(_pGameTime);
            base.Update(_pGameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself. 
        /// </summary>
        protected override void Draw(GameTime _pGameTime)
        {
            mpGameEngine.Draw(_pGameTime);
            base.Draw(_pGameTime);
        }

        #endregion

        /// <summary>
        /// Default constructor, launch the <typeparamref name="GameEngine"/>.
        /// </summary>
        public Game()
        {
            // Initialize Game
            mpSingletonInstance = this;
            mpGameEngine = new GameEngine(this);
            mpGameEditor = new GameEditor();
        }
    }
}
